//
//  UIBarButtonItem+Extensions.swift
//  MicroBlog
//
//  Created by ChenJunWen on 2017/11/28.
//  Copyright © 2017年 CJW. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    convenience init(title: String, fontsize: CGFloat = 16, target: AnyObject?, action: Selector, isBack: Bool = false) {
        let btn: UIButton = UIButton.jw_textButton(title, fontSize: fontsize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        
        if isBack { // 带返回键icon
            let imageName = "navigationbar_back_withtext"
            
            btn.setImage(UIImage(named: imageName), for: .normal)
            btn.setImage(UIImage(named: imageName + "_highlighted"), for: .highlighted)
            
            btn.sizeToFit()
        }
        
        
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        // 设置便利构造函数,需要实例化当前类 通过self.init实例化
        self.init(customView: btn)
    }
}

